package controller.backstage;

import dao.backstage.GoodsDao;
import dao.backstage.impl.GoodsDaoImpl;
import pojo.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;

@WebServlet(name = "updateGoodsServlet",value = "/updateGoods")
public class updateGoodsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String goods_name = req.getParameter("goods_name");
        String picture = req.getParameter("picture");
        String price = req.getParameter("price");
        String type_id = req.getParameter("type_id");
        String detail = req.getParameter("detail");
        System.out.println("update id is :"+id);
        GoodsDao goodsDao = new GoodsDaoImpl();

        Goods goods = new Goods(Integer.parseInt(id),goods_name,picture, BigDecimal.valueOf(Long.parseLong(price)),Integer.parseInt(type_id),detail);
        goodsDao.updateGoods(goods);
//        req.getRequestDispatcher("/goodsAll.jsp").forward(req,resp);
        resp.sendRedirect("/goodsAll.jsp");
        System.out.println(goods.toString());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}

